<template>
  <div class="notice-page">
    <van-nav-bar
      :title="$t('zixun24')"
      left-arrow
      @click-left="onClickLeft"
      style="background-color: var(--ex-home-box-background-color);"
    />

    <div class="notice-list">
      <div
        class="notice-item"
        v-for="(news, index) in newsList"
        :key="news.id"
        @click="goToDetail(news.id)"
      >
        <div class="notice-index">{{ index + 1 }}</div>
        <div class="notice-title">{{ news.question }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { getHelpcenter } from '@/api/help/index'
import { ref, computed, onMounted } from 'vue'

const router = useRouter()

const list = ref([{ infoList: [] }])
const newsList = computed(() => list.value[0]?.infoList || [])

const onClickLeft = () => history.back()

const goToDetail = (id) => {
  router.push(`/zxDetail/${id}`)
}

onMounted(async () => {
  try {
    const res = await getHelpcenter()
    if (res.code === 200) {
      list.value = res.data && res.data.length > 0 ? res.data : [{ infoList: [] }]
    }
  } catch (error) {
    console.error('Error fetching help center data:', error)
  }
})
</script>

<style scoped lang="scss">
.notice-page {
  background: #f7f8fa;
  min-height: 100vh;
}

:deep(.van-nav-bar__title) {
  color: #000;
  font-weight: 700;
}

.notice-list {
  padding: 16px;
}

.notice-item {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  padding: 16px 14px;
  margin-bottom: 14px;
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  }

  .notice-index {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background-color: #2248f3;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
  }

  .notice-title {
    font-size: 15px;
    color: #111;
    font-weight: 600;
    line-height: 1.5;
    word-break: break-all;
  }
}
</style>
